package com.lyt.controller;

import com.alibaba.fastjson.JSON;
import com.lyt.bean.Question;
import com.lyt.bean.User;
import com.lyt.service.QuestionService;
import com.lyt.vo.QuestionVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @Author: zjx
 * @Date: 2023/04/27/20:03
 * @Description:
 */
@RestController
@CrossOrigin
public class QuestionController {
    @Autowired
    QuestionService  questionService;

    @RequestMapping("/question/edit")//添加试题
    public String addQuestion(@RequestBody QuestionVo questionVo)throws Exception{
//        System.out.println(questionVo);
        questionService.addQuestion(questionVo);

//        questionService.addQuestion(questionVo);
        return "ok";
    }

    @RequestMapping("/question/get")//查询所有试题
    public List<QuestionVo> getAllQuestion()throws Exception{
//        System.out.println(questionVo);

//        questionService.addQuestion(questionVo);
        return questionService.getAllQuestion();
    }

    @RequestMapping("/question/id")//根据id查询试题
    public QuestionVo getQuestionListById(@Param("id") Integer id)throws Exception{
//        System.out.println(questionVo);

//        questionService.addQuestion(questionVo);
        return questionService.getQuestionById(id);
    }

    @RequestMapping("/question/questionList")
    public List<Question> questionList(){
//        System.out.println(questionVo);

//        questionService.addQuestion(questionVo);
        return questionService.questionList();
    }

    //zjx
    @RequestMapping("/question/delete/{id}")
    public int deleteQuestion(@PathVariable("id") Integer id)throws Exception{
        return questionService.deleteQuestion(id);
    }

    //zjx
    @RequestMapping("/question/courseIdortype")
    public List<QuestionVo> getAllQuestionByCourseIdOrType(@Param("type") Integer type,@Param("courseId")Integer courseId)throws Exception{
        return questionService.getAllQuestionByCourseIdOrType(type,courseId);
    }

    //zjx 5/7
    @RequestMapping("/question/courseId")//根据课程Id查询试题
    public List<QuestionVo> getAllByCourseQuestion(@Param("courseId") Integer courseId)throws Exception{
        return questionService.getAllByCourseQuestion(courseId);
    }

    //zjx 5/7
    @RequestMapping("/question/type")//根据课程Id查询试题
    public List<QuestionVo> getAllBytypeuestion(@Param("type") Integer type)throws Exception{
        return questionService.getAllBytypeuestion(type);
    }

    //zjx 5/8
    @RequestMapping("/question/update")//根据课程Id查询试题
    public int getAllBytypeuestion(@RequestBody QuestionVo questionVo)throws Exception{
        questionService.updateQuestion(questionVo);
        return 1;
    }
}
